package com.zhenwei.zscm.controller;

import com.zhenwei.zscm.common.annotations.MethodName;
import com.zhenwei.zscm.common.annotations.Update;
import com.zhenwei.zscm.common.base.RestResult;
import com.zhenwei.zscm.model.dto.roleAuth.RoleAuthDTO;
import com.zhenwei.zscm.model.vo.roleAuth.RoleAuthVO;
import com.zhenwei.zscm.service.RoleAuthService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("/api/role/auth")
@MethodName("角色权限管理")
public class RoleAuthController {
    private RoleAuthService roleAuthService;

    @GetMapping("/detail")
    @MethodName("获取角色权限")
    public RestResult detail(@RequestParam @NotEmpty(message = "角色不能为空") String role) {
        return roleAuthService.getRoleAuth(role);
    }

    @GetMapping("/list")
    @MethodName("获取角色权限列表")
    public RestResult list() {
        return roleAuthService.list();
    }

    @MethodName("添加角色权限")
    @PostMapping("/create")
    public RestResult create(@RequestBody @Valid RoleAuthDTO roleAuthDTO) {
        return roleAuthService.createRoleAuth(roleAuthDTO);
    }

    @MethodName("修改角色权限")
    @PostMapping("/update")
    public RestResult update(@RequestBody @Valid RoleAuthDTO dto) {
        return roleAuthService.updateRoleAuth(dto);
    }

    @MethodName("修改角色菜单权限")
    @PostMapping("/updateMenuAuth")
    public RestResult updateMenuAuth(@RequestBody @Validated(Update.class) RoleAuthVO vo) {
        return roleAuthService.updateMenuAuth(vo);
    }

    @MethodName("修改角色接口权限")
    @PostMapping("/updateApiAuth")
    public RestResult updateApiAuth(@RequestBody @Validated(Update.class) RoleAuthVO vo) {
        return roleAuthService.updateApiAuth(vo);
    }

    @MethodName("判断是否有菜单权限")
    @GetMapping("/checkMenuAuth")
    public RestResult checkMenuAuth(@RequestParam @NotEmpty(message = "菜单标识不能为空") String menuCode ) {
        return roleAuthService.checkMenuAuth(menuCode);
    }
}
